/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CourseFrame.java
 *
 * Created on 09.12.2011, 10:55:07
 */
package de.aeo.bll;

import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;
/**
 * @author Frederic Branczyk & Robert Piwonski
 */
public class CourseFrame extends javax.swing.JFrame {
    
    private Algorithm a;
    private DefaultTableModel dtm;

    /** Creates new form CourseFrame */
    public CourseFrame(Algorithm a) {
        this.a = a;
        String[] header = {
            this.a.getLanguageString("class"),
            this.a.getLanguageString("name")
        };
        dtm = new DefaultTableModel(null, header);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelCourse1 = new javax.swing.JLabel();
        jTextFieldCourse1 = new javax.swing.JTextField();
        jLabelCourse2 = new javax.swing.JLabel();
        jTextFieldCourse2 = new javax.swing.JTextField();
        jButton1to2 = new javax.swing.JButton();
        jButton2to1 = new javax.swing.JButton();
        jLabelAutoselect = new javax.swing.JLabel();
        jComboBoxSubjects = new javax.swing.JComboBox();
        jLabelCount1 = new javax.swing.JLabel();
        jLabelCount2 = new javax.swing.JLabel();
        jLabelCountLabel2 = new javax.swing.JLabel();
        jLabelCountLabel1 = new javax.swing.JLabel();
        jButtonApply = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();

        setResizable(false);

        jLabelCourse1.setText(this.a.getLanguageString("course")+":");

        jLabelCourse2.setText(this.a.getLanguageString("course")+":");

        jButton1to2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/de/aeo/bll/arrowRight.png"))); // NOI18N

        jButton2to1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/de/aeo/bll/arrowLeft.png"))); // NOI18N

        jLabelAutoselect.setText(this.a.getLanguageString("selectAllStudentsWithTheCourse"));

        jLabelCount1.setText("0");

        jLabelCount2.setText("0");

        jLabelCountLabel2.setText(this.a.getLanguageString("amount")+":");

        jLabelCountLabel1.setText(this.a.getLanguageString("amount")+":");

        jButtonApply.setText(this.a.getLanguageString("apply"));
        jButtonApply.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonApplyActionPerformed(evt);
            }
        });

        jTable1.setModel(this.dtm);
        jScrollPane1.setViewportView(jTable1);

        jTable2.setModel(this.dtm);
        jScrollPane2.setViewportView(jTable2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabelCountLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabelCount1))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabelCourse1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldCourse1, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE))
                            .addComponent(jLabelAutoselect)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jButton1to2)
                                    .addComponent(jButton2to1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabelCourse2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldCourse2, javax.swing.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE))
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabelCountLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabelCount2))
                            .addComponent(jButtonApply))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jComboBoxSubjects, 0, 244, Short.MAX_VALUE)
                        .addGap(317, 317, 317))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCourse1)
                    .addComponent(jTextFieldCourse1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldCourse2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelCourse2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(jButton1to2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2to1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabelCount2)
                                    .addComponent(jLabelCountLabel2)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabelCount1)
                                    .addComponent(jLabelCountLabel1))))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonApply)
                        .addGap(16, 16, 16))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelAutoselect)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(jComboBoxSubjects, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(17, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonApplyActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonApplyActionPerformed

    public void setLists(ArrayList<Student> list1, ArrayList<Student> list2, ArrayList<Subject> subjectList) {
        int i = 0;
        String data1[][] = new String[list1.size()][2];
        for(Student s:list1) {
            String str[] = {null, null};
            str[0] = s.getcClass();
            str[1] = s.getFirstname()+" "+s.getLastname();
            data1[i] = str;
            i++;
        }
        i = 0;
        String data2[][] = new String[list1.size()][2];
        for(Student s:list1) {
            String str[] = {null, null};
            str[0] = s.getcClass();
            str[1] = s.getFirstname()+" "+s.getLastname();
            data2[i] = str;
            i++;
        }
        
        String[] header = {
            this.a.getLanguageString("class"),
            this.a.getLanguageString("name")
        };
        
        DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
        for(Subject s:subjectList) {
            dcbm.addElement(s);
        }
        
        this.jTable1.setModel(new DefaultTableModel(data1, header));
        this.jTable2.setModel(new DefaultTableModel(data2, header));
        this.jComboBoxSubjects.setModel(dcbm);
    }
    
//    public static void main(String[] args) {
//        CourseFrame cf = new CourseFrame(new Manager());
//        cf.setVisible(true);
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1to2;
    private javax.swing.JButton jButton2to1;
    private javax.swing.JButton jButtonApply;
    private javax.swing.JComboBox jComboBoxSubjects;
    private javax.swing.JLabel jLabelAutoselect;
    private javax.swing.JLabel jLabelCount1;
    private javax.swing.JLabel jLabelCount2;
    private javax.swing.JLabel jLabelCountLabel1;
    private javax.swing.JLabel jLabelCountLabel2;
    private javax.swing.JLabel jLabelCourse1;
    private javax.swing.JLabel jLabelCourse2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField jTextFieldCourse1;
    private javax.swing.JTextField jTextFieldCourse2;
    // End of variables declaration//GEN-END:variables
}
